package com.winit.requirement.web;

import com.winit.common.base.web.BaseController;
import com.winit.requirement.manager.ReqRemarkManager;
import com.winit.requirement.model.ReqRemark;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "brd", tags = {"reqRemark"}, description = "reqRemark")
@RestController
@RequestMapping("/api/v1/reqRemark")
public class ReqRemarkController extends BaseController {

    private static Logger log = LoggerFactory.getLogger(ReqRemarkController.class);

    @Autowired
    private ReqRemarkManager reqRemarkManager;


    @RequestMapping(value = "/saveReqRemark", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "创建/更新ReqRemark")
    @ResponseBody
    public Map saveReqRemark(@RequestBody ReqRemark reqRemark){
        if (null == reqRemark){
            log.error("没有接收到参数.");
            return this.getRtn(BaseController.REQUEST_ERROR, "没有接收到参数.", null);
        }
        ReqRemark rs = null;
        if (StringUtils.isEmpty(reqRemark.getId())){
            log.info("没有id，将执行新增操作");
            rs = this.reqRemarkManager.createReqRemark(reqRemark);
        }else {
            log.info("执行更新操作");
            rs = this.reqRemarkManager.updateReqRemark(reqRemark);
        }
        return this.getRtn(BaseController.REQUEST_SUCCESS, BaseController.REQUEST_SUCCESS_MSG, rs);
    }

    @RequestMapping(value = "/getReqRemarks", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "查询ReqRemark")
    @ResponseBody
    public Map getReqRemarks(@ApiParam(value = "id，remark id")@RequestParam(value = "id", required = false)String id,
                             @ApiParam(value = "number")@RequestParam(value = "number", required = false)String number,
                             @ApiParam(value = "reqId，上线的reqIds")@RequestParam(value = "reqId", required = false)String reqId){
        List<ReqRemark> reqRemarks = this.reqRemarkManager.getReqRemarks(id, number, reqId);
        return this.getRtn(BaseController.REQUEST_SUCCESS, BaseController.REQUEST_SUCCESS_MSG, reqRemarks);
    }


    @RequestMapping(value = "/deleteReqRemark", method = RequestMethod.GET)
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "删除ReqRemark")
    @ResponseBody
    public Map deleteReqRemark(@ApiParam(value = "id，remark id")@RequestParam(value = "id", required = false)String id){
        this.reqRemarkManager.deleteReqRemark(id);
        return this.getRtn(BaseController.REQUEST_SUCCESS, BaseController.REQUEST_SUCCESS_MSG);
    }
}
